compio_driver\sys\op\asyncify/
iocp.rs1use windows_sys::Win32::System::IO::OVERLAPPED;
2
3use crate::{OpCode, OpType, sys::op::*};
4
5unsafe impl<D, F> OpCode for Asyncify<F, D>
6where
7 D: std::marker::Send + 'static,
8 F: (FnOnce() -> BufResult<usize, D>) + std::marker::Send + 'static,
9{
10 type Control = ();
11
12 fn op_type(&self, _: &Self::Control) -> OpType {
13 OpType::Blocking
14 }
15
16 unsafe fn operate(&mut self, _: &mut (), _: *mut OVERLAPPED) -> Poll<io::Result<usize>> {
17 let f = self
18 .f
19 .take()
20 .expect("the operate method could only be called once");
21 let BufResult(res, data) = f();
22 self.data = Some(data);
23 Poll::Ready(res)
24 }
25}
26
27unsafe impl<S, D, F> OpCode for AsyncifyFd<S, F, D>
28where
29 S: std::marker::Sync,
30 D: std::marker::Send + 'static,
31 F: (FnOnce(&S) -> BufResult<usize, D>) + std::marker::Send + 'static,
32{
33 type Control = ();
34
35 fn op_type(&self, _: &Self::Control) -> OpType {
36 OpType::Blocking
37 }
38
39 unsafe fn operate(&mut self, _: &mut (), _: *mut OVERLAPPED) -> Poll<io::Result<usize>> {
40 let f = self
42 .f
43 .take()
44 .expect("the operate method could only be called once");
45 let BufResult(res, data) = f(&self.fd);
46 self.data = Some(data);
47 Poll::Ready(res)
48 }
49}
50
51unsafe impl<S1, S2, D, F> OpCode for AsyncifyFd2<S1, S2, F, D>
52where
53 S1: std::marker::Sync,
54 S2: std::marker::Sync,
55 D: std::marker::Send + 'static,
56 F: (FnOnce(&S1, &S2) -> BufResult<usize, D>) + std::marker::Send + 'static,
57{
58 type Control = ();
59
60 fn op_type(&self, _: &Self::Control) -> OpType {
61 OpType::Blocking
62 }
63
64 unsafe fn operate(&mut self, _: &mut (), _: *mut OVERLAPPED) -> Poll<io::Result<usize>> {
65 let f = self
67 .f
68 .take()
69 .expect("the operate method could only be called once");
70 let BufResult(res, data) = f(&self.fd1, &self.fd2);
71 self.data = Some(data);
72 Poll::Ready(res)
73 }
74}